<template>
<!-- 隐私协议 -->
    <div class='privacy'>
        <div class="addserve" :style='{top:styleall}'>
            <el-button @click="addserve" class="fr" size="small" type="primary">保存</el-button>
        </div>
        <editor v-model="noticeContent" :min-height="192"/>
    </div>
</template>
<script>
import { selectPages,addPageValue,updatePageValue} from "@/api/pc.js"
export default {
    name:'Privacy',
    data(){
       return{
            noticeContent:'',
            // 样式
            styleall:{},
       }
    },
    mounted(){this.getdata();window.addEventListener('scroll',this.handleScroll);},
    methods:{
        // 滚动事件
        handleScroll(){
            // 滚动条偏移量
            let scrollTop = document.documentElement.scrollTop;
            if(scrollTop>80){this.styleall ='0px';}else{ this.styleall =(80 - scrollTop) +'px'; }
        },
        // 保存
        addserve(){
            let objall = {
                noticeContent:this.noticeContent
            }
            let obj={pageName:'隐私协议',pageType:'privacy',pageValue:JSON.stringify(objall),}
            if(!this.edit){
                addPageValue(obj).then(res=>{
                    console.log(res)
                    if(res.code==200){this.$message.success('保存成功！')}
                })
            }else{
                obj.pageId = this.pageId;
                updatePageValue(obj).then(res=>{
                    console.log(res)
                    if(res.code==200){this.$message.success('更新成功！')}
                })
            }
        },
        // 获取数据
        getdata(){
            selectPages({pageType:'privacy'}).then(res=>{
                if(res.code==200){
                    console.log(JSON.parse(res.data[0].pageValue))
                    if(res.data.length==0){
                        this.edit = false;
                    }else{
                        this.edit = true;
                        this.pageId = res.data[0].pageId;
                        let obk = JSON.parse(res.data[0].pageValue);
                        this.noticeContent = obk.noticeContent;
                    }
                }
            })
        },
    }
}
</script>
<style lang='scss' scoped>
.privacy{
    width: 100%;
    height: 100%;
    padding: 20px;
    padding-top: 60px;
}
.addserve{
    width: 100%;
    height: 40px;
    position: fixed;
    top:80px;
    left: 0;
    background-color: #fff;
    padding-right: 30px;
    z-index: 101;
    button{
        margin-top: 4px;
        width: 100px;
    }
}
</style>